package org.azj.fieldTypeConverter;

import javax.swing.JOptionPane;

import org.azj.logHelper.LOG;
import org.azj.logHelper.LOG_COMPONENT;
import org.azj.logHelper.LOG_LEVEL;

// 根据输入的字段类型选择格式转换器
public class ConverterFactory {
	public static ITypeConverter GetConverterByFieldType(FieldType type)
	{
		if (type == FieldType.CHAR || type == FieldType.VARCHAR){
			return new CharConverter();
		}
		
		if (type == FieldType.DATE)
		{
			return new DateConverter();
		}
		
		if (type == FieldType.INTEGER)
		{
			return new IntConverter();
		}
		
		if (type == FieldType.DECIMAL)
		{
			return new DecimalConverter();
		}
		
		if (type == FieldType.BLOB)
		{
			return new BlobConverter();
		}
		
		JOptionPane.showMessageDialog(
				null, "出现数据库未定义数据类型!", "错误", JOptionPane.ERROR_MESSAGE);
		LOG.WriteLog(LOG_LEVEL.CRITICAL, LOG_COMPONENT.LOG_COMP_DB_CHANGE, "出现数据库未定义数据类型" + type.toString());
		return null;
	}
	
	public static ITypeConverter GetConverterByFieldType(String type)
	{
		return GetConverterByFieldType(FieldType.valueOf(type));
	}
}
